from django.db import models
from datetime import datetime
from users.models import UserProfile, onceName


# 树洞分类名
class treeHoleClass(models.Model):
    title = models.CharField(max_length=10, verbose_name=u"树洞分类")
    show = models.BooleanField(verbose_name=u"显示分类", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"树洞分类"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title

    def __str__(self):
        return self.title


# 点赞显示名字
class agreeName(models.Model):
    name = models.CharField(max_length=10, verbose_name=u"点赞名", default="喜欢")
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"点赞名"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.name

    def __str__(self):
        return self.name


# 树洞
class treeHole(models.Model):
    treeholeclass = models.ForeignKey(treeHoleClass, verbose_name=u"树洞分类")
    title = models.CharField(max_length=10, verbose_name=u"树洞名")
    agreeName = models.ForeignKey(agreeName, verbose_name=u"点赞名")
    ask = models.CharField(max_length=20, verbose_name=u"树洞创建问答")
    text = models.CharField(max_length=20, verbose_name=u"树洞创建提示")
    input = models.CharField(max_length=30, verbose_name=u"树洞文本框提示")
    show = models.BooleanField(verbose_name=u"显示树洞", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"树洞"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title

    def __str__(self):
        return self.title


# 秘密&树洞话题
class topicofc(models.Model):
    treeHole = models.ForeignKey(treeHole, verbose_name=u"树洞")
    content = models.CharField(max_length=20, verbose_name=u"话题内容")
    show = models.BooleanField(verbose_name=u"显示话题", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"秘密话题"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.content

    def __str__(self):
        return self.content


class secret(models.Model):
    treeHole = models.ForeignKey(treeHole, verbose_name=u"树洞")
    onceName = models.ForeignKey(onceName, verbose_name=u"用户曾用名")
    topicofc = models.ForeignKey(topicofc, null=True, blank=True, verbose_name=u"秘密话题")
    title = models.CharField(max_length=10, verbose_name=u"秘密名字")
    weather = models.CharField(max_length=10, verbose_name=u"天气", default="晴")
    temperature = models.CharField(max_length=10, verbose_name=u"温度", default="27~34℃")
    content = models.TextField(verbose_name=u"秘密内容")
    Interaction = models.BooleanField(verbose_name=u"允许互动", default=True)
    show = models.BooleanField(verbose_name=u"显示秘密", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"秘密"
        ordering = ['-time']
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title

    def __str__(self):
        return self.title


class imgs(models.Model):
    secret = models.ForeignKey(secret, verbose_name=u"点赞秘密")
    img = models.ImageField(upload_to="img/%Y/%m", null=True, verbose_name=u"秘密图片")
    show = models.BooleanField(verbose_name=u"显示图片", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"秘密图片"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.secret.title

    def __str__(self):
        return self.secret.title


class agree(models.Model):
    user = models.ForeignKey(UserProfile, verbose_name=u"点赞用户", null=True)
    secret = models.ForeignKey(secret, verbose_name=u"点赞秘密")
    show = models.BooleanField(verbose_name=u"显示点赞", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"秘密点赞"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.user + self.secret.content

    def __str__(self):
        return self.secret.content


class comment(models.Model):
    secret = models.ForeignKey(secret, verbose_name=u"秘密")
    onceName = models.ForeignKey(onceName, verbose_name=u"用户曾用名")
    SuperiorComment = models.ForeignKey('self', null=True, blank=True, verbose_name=u"回复评论Id")
    content = models.TextField(verbose_name=u"评论内容")
    show = models.BooleanField(verbose_name=u"显示评论", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"秘密评论&回复"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.secret.onceName.name

    def __str__(self):
        return self.content


class reporTreason(models.Model):
    content = models.TextField(verbose_name=u"举报选项")
    show = models.BooleanField(verbose_name=u"显示举报", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"举报选项"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.content

    def __str__(self):
        return self.content


class reportAlready(models.Model):
    reporTreason = models.ForeignKey(reporTreason, verbose_name=u"举报选项")
    user = models.ForeignKey(UserProfile, verbose_name=u"举报用户")
    secret = models.ForeignKey(secret, verbose_name=u"举报秘密")
    comment = models.ForeignKey(comment, null=True, blank=True, verbose_name=u"举报评论")
    show = models.BooleanField(verbose_name=u"显示举报成功", default=True)
    time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
    isDelete = models.BooleanField(verbose_name=u"逻辑删除", default=False)

    class Meta:
        verbose_name = u"举报成功"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.reporTreason.content

    def __str__(self):
        return self.reporTreason.content